|
Managing a cross-table from the script If setting table visual resources are not enough, one can use the script for detailed settings for the appearance of the table. The "Cross-table" object has the following events:
It is convenient to use the following methods of the "Cross-table" object in events:
Let us exemplify, how one can highlight the third column (in our example it is the "November 1999" date). To perform this, select a cross-table and create the OnPrintCell event’s handler: procedure Cross1OnPrintCell(Memo: TfrxMemoView; We will see the following result:
To highlight a column title, create an "OnPrintColumnHeader" event’s handler: procedure Cross1OnPrintColumnHeader(Memo: TfrxMemoView; Result would appear as follows:
Let us explain how the scripts work. The "OnPrintCell" event handler is called before printing a cell included in the table’s body (when printing cells from the table title, either the "OnPrintColumnHeader," or the "OnPrintRowHeader" handler is called). At the same time, a link to the "Text" object, which represents a table’s cell ("Memo" parameter), and the cell’s "address" in two variants: the number of row, column and cell (the last is relevant, if your table contains multi-leveled cells) in the "RowIndex," "ColumnIndex," and "CellIndex" parameters respectively, are transmitted into the "OnPrintCell" handler. The "RowValues" and the "ColumnValues" parameters are the second variant of the "address." The "Value" parameter is the cell’s contents. To specify an "address," you can use the second variant (RowValues, ColumnValues), since it is more convenient in the given case (as well as the first one (RowIndex, ColumnIndex)). In our case, it was necessary to highlight the third column; therefore, it would be more convenient to analyze the first variant. Since numbering of columns and rows begins with "0," the "ColumnIndex = 2" checking allows us to define the third column. One could do it in a different way, i.e. by analyzing the required column by its data (we need the 11th month of 1999): procedure Cross1OnPrintCell(Memo: TfrxMemoView; Values, which are transferred in the "RowValues" and the "ColumnValues" parameters, are arrays of the "Variant" type with a zero base. The zero element is a value of the highest level of the table’s title; the first one is a value of the next level, etc. In our case, the "ColumnValues[0]" contains years, and the "ColumnValues[1]" contains months. Why is "VarToStr" transformation necessary? This guarantees absence of mistakes during type conversion. When operating with the "Variant" type, Delphi attempts to automatically cast the strings to number format, which, in its turn, can lead to an error when attempting to cast the "Total" and "Grand Total'" columns’ values. The "OnPrintColumnHeader" event handler is called during typing column title cells. The set of parameters is similar to the parameters of the "OnPrintCell" handler, although in this case the cell’s "address" (the "HeaderIndexes" and "HeaderValues" parameters) is transferred in a different way. The "HeaderValues" parameter returns the same values, as the "ColumnValues" and "RowValues" parameters in the "OnPrintCell" handler. The "HeaderIndexes" parameter is also an array of values of the "Variant" type, which contains an address of the title’s cell in a different form: the zero element is the serial number of the highest level of the table’s title, the first one is the number of the next level, etc. To make the principle of cells numbering clear, refer to the picture below:
In our case, it is more convenient to analyze the "HeaderValues" value, but one can write the following handler as well: procedure Cross1OnPrintColumnHeader(Memo: TfrxMemoView; |
||||||||||||||||||||||||||||||||